/*
 * Created by: Peter Weissbrod
 * Created: Tuesday, January 22, 2008
 */
using System.Data.SqlTypes;
using NUnit.Framework;
using PostSharp.UserSamples.Exceptions;
using PostSharp.UserSamples.Validators;
using System;

namespace PostSharp.UserSamples.Tests
{
    [TestFixture]
    public class TestAttributes
    {
        #region setup/teardown
        [TestFixtureSetUp]
        public void SetUp()
        {
        }
        [TestFixtureTearDown]
        public void TearDowm()
        {
        }
        #endregion

        #region tests
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestBadRegex()
        {
            TestDummy dummy = new TestDummy();
            dummy.Email = "foo";
        }
        [Test]
        public void TestGoodRegex()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Email = "someone@something.com";
        }
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestAboveMaxLength()
        {
            TestDummy _dummy = new TestDummy();
            _dummy.String = "somereallylongname@somecompanythatistoolongtofitin30characters.com";
        }
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestBelowMinLength()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Email = string.Empty;
        }
        [Test]
        public void TestGoodLength()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.String = "a string of the right length";
        }
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestBadNull()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Nullable = null;
        }
        [Test]
        public void TestGoodNull()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Nullable = new object();
        }
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestFloatBelowRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Float = -1f;
        }
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestFloatAboveRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Float = 21f;
        }
        [Test]
        public void TestFloatInRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Float = 10;
        }
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestIntBelowRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Int = -1;
        }
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestIntAboveRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Int = 21;
        }
        [Test]
        public void TestIntInRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.Int = 10;
        }
        [Ignore("Still working on this validator")]
        [Test]
        [ExpectedException(typeof(ValidationException))]
        public void TestBelowSqlDateTimeRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.DateTime = DateTime.MinValue;
        }
        [Ignore("Still working on this validator")]
        [Test]
        public void TestInRangeSqlDateTimeRange()
        {
            TestDummy _testDummy = new TestDummy();
            _testDummy.DateTime = DateTime.Now;
        }
        #endregion
    }
    public class TestDummy
    {
        [RegExValidator(RegularExpression = @"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$")]
        public string Email
        {
            get;
            set;
        }
        [IntegerRangeValidator(MinVal = 0,MaxVal = 20)]
        public int Int
        {
            get;
            set;
        }
        [StringLengthValidator(MinLength = 1, MaxLength = 30)]
        public string String
        {
            get;
            set;
        }
        [FloatRangeValidator(MinVal = 0, MaxVal = 20)]
        public float Float
        {
            get;
            set;
        }
        [NotNullValidator]
        public object Nullable
        {
            get;
            set;
        }
        [SqlDateTimeRangeValidator]
        public DateTime DateTime
        {
            get;
            set;
        }
    }
}